<?php
	class User_cart_model extends CI_Model {
		private $table_name="user_cart";
	 public function get_by_user($prodect_id,$user_id){
	 	$query=$this->db->where(array('prodect_id'=>$prodect_id,'user_id'=>$user_id))->get($this->table_name);
	 	return $query->row();
	 } 
	 public function get_add_shopcart($prodect_id,$user_id,$num){
	 	$this->db->insert($this->table_name,array(
	 			'prodect_id'=>$prodect_id,
	 			'user_id'=>$user_id,
	 			'num'=>$num
	 		));
	 }
	 public function update_shopcart($prodect_id,$user_id,$num){
   		$this->db->query("update $this->table_name set `num`=`num`+$num where `prodect_id`=$prodect_id and `user_id`=$user_id");
	}
	public function cart_count($user_id){
		$query=$this->db->where("user_id",$user_id)->get($this->table_name);
		return count($query->result());
	}
	public function get_user($user_id){
		$query=$this->db->where("user_id",$user_id)->get($this->table_name);
		return $query->result();
	}
	public function del($id){
		$this->db->where('id',$id)->delete($this->table_name);
	}
	public function delcart($ids){
		$this->db->where_in("id",$ids)->delete($this->table_name);
	}
	public function update($id,$num){
		$this->db->where('id',$id)->update($this->table_name,array(
				'num'=>$num
			));
	}
}

    
